package com.ruoyi.carowner.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.carowner.domain.CarownerWxpay;
import com.ruoyi.carowner.service.ICarownerWxpayService;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 车主微信支付Controller
 *
 * @author ruoyi
 * @date 2024-08-19
 */
@RestController
@RequestMapping("/carowner/wxpay")
public class CarownerWxpayController extends BaseController {
    @Autowired
    private ICarownerWxpayService carownerWxpayService;

    /**
     * 查询车主微信支付列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:wxpay:list')")
    @GetMapping("/list")
    public TableDataInfo list(CarownerWxpay carownerWxpay) {
        startPage();
        List<CarownerWxpay> list = carownerWxpayService.selectCarownerWxpayList(carownerWxpay);
        return getDataTable(list);
    }

    /**
     * 导出车主微信支付列表
     */
    @PreAuthorize("@ss.hasPermi('carowner:wxpay:export')")
    @Log(title = "车主微信支付", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CarownerWxpay carownerWxpay) {
        List<CarownerWxpay> list = carownerWxpayService.selectCarownerWxpayList(carownerWxpay);
        ExcelUtil<CarownerWxpay> util = new ExcelUtil<CarownerWxpay>(CarownerWxpay.class);
        util.exportExcel(response, list, "车主微信支付数据");
    }

    /**
     * 获取车主微信支付详细信息
     */
    @PreAuthorize("@ss.hasPermi('carowner:wxpay:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Integer id) {
        return success(carownerWxpayService.selectCarownerWxpayById(id));
    }

    //根据用户id获取微信余额
    @GetMapping("/getByUserId/{userId}")
    public AjaxResult getByUserId(@PathVariable Integer userId) {
        return success(carownerWxpayService.selectWxpayByUserId(userId));
    }

    /**
     * 新增车主微信支付
     */
    @PreAuthorize("@ss.hasPermi('carowner:wxpay:add')")
    @Log(title = "车主微信支付", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CarownerWxpay carownerWxpay) {
        return toAjax(carownerWxpayService.insertCarownerWxpay(carownerWxpay));
    }

    /**
     * 修改车主微信支付
     */
    @PreAuthorize("@ss.hasPermi('carowner:wxpay:edit')")
    @Log(title = "车主微信支付", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CarownerWxpay carownerWxpay) {
        return toAjax(carownerWxpayService.updateCarownerWxpay(carownerWxpay));
    }

    /**
     * 删除车主微信支付
     */
    @PreAuthorize("@ss.hasPermi('carowner:wxpay:remove')")
    @Log(title = "车主微信支付", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Integer[] ids) {
        return toAjax(carownerWxpayService.deleteCarownerWxpayByIds(ids));
    }
}
